#ifndef CHAT_CLIENT_H
#define CHAT_CLIENT_H

#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>

#include "GameMessage.h"
#include "Connection.h"
#include "Observable.h"
#include <Player.h>

using boost::asio::ip::tcp;

class GameClient : public Observable
{
public:
	GameClient(boost::asio::io_service& io_service, tcp::endpoint& endpoint, Player& login);
    GameClient();

    void connect(boost::asio::io_service& io_service,tcp::endpoint& endpoint,Player& login);

	// fonction to send datas
    void	write					(GameMessage& e); // Envoyer un event quelconque
	void	write				    (const std::string& msg); // Envoyer un message

	// Close the connection
	void	close	();
    Player& get_login();
private:
    
	void handle_connect		(const boost::system::error_code& error);
	void handle_read		(const boost::system::error_code& error);
	void handle_write		(const boost::system::error_code& error);

	void do_close			();

 private:
    boost::asio::io_service*	m_io_service;
    connection_ptr				m_tcp_connection;
    GameMessage				m_message_read;
	Player					m_login;
};


#endif
